-
"Build tool for build tools".
-
Generate build files for other tools (do not compile directly).
-
Allow cross-platform configuration (Linux, Windows, macOS).
-
Use languages or DSLs (CMakeLists.txt, Meson.build, etc.).
-
"Great for working with different compilers in different types of systems".
CMake
-
CMake .
-
Cross-platform.
-
My version :
-
cmake-3.31.3-windows-x86_64.msi.
-
-
Can use Make, Ninja, etc.
Commands
-
cmake-
Starts CMake.
-
-
-S "./../"-
Sets the source directory where the
CMakeLists.txtis. -
Here: The source directory is the parent of the current directory (
./../).
-
-
-B "vs2022_x64"-
Sets the build directory where CMake and Visual Studio generated files will be placed.
-
Here:
vs2022_x64.
-
-
-G "Visual Studio 17 2022"-
Specifies the generator, i.e., the type of project to generate.
-
Here: Solution for Visual Studio 2022.
-
-
-A x64-
Sets the build architecture .
-
Here: 64-bit.
-
-
-DCMAKE_INSTALL_PREFIX:String="SDK"-
Sets the
CMAKE_INSTALL_PREFIXvariable to"SDK".-
Defines the installation path for project artifacts (e.g., when running
cmake --installor theINSTALLtarget).
-
-
Here:
"SDK"will be the installation prefix. -
Note:
:Stringis redundant here. CMake correctly interprets-DVAR=VALUEwithout type.
-
-
-DCMAKE_BUILD_TYPE:String=Distribution-
Sets
CMAKE_BUILD_TYPEto"Distribution".-
Single-config builds (like Makefile or Ninja).
-
-
Note : Ignored in multi-config generators like Visual Studio, where build type (Debug/Release/etc.) is selected in the IDE or via
--config.
-
-
%*-
Inserts all arguments passed to the script/batch.
-
Allows passing additional arguments.
-
Breaking when moving
-
CMakeCache.txtstores absolute paths to source and build directories. -
Visual Studio project files generated by CMake (like
.vcxproj) also reference absolute paths. -
If you move the folder, these paths become invalid, causing build errors or inability to open in Visual Studio.
-
Options :
-
Recreate the build folder:
-
Delete the build folder (not the source folder).
-
Move the source folder to the new location.
-
Recreate the build directory in the new location:
cmake .. -G "Visual Studio 17 2022" -
Open the generated
.slnfile in Visual Studio again.
-
-
Delete all CMake-generated files.
-
CMakeCache.txt -
CMakeFiles/ -
All
.vcxproj,.sln,.user,.filters, etc. -
Move the folder to the new location.
-
Reconfigure with CMake:
cmake .. -G "Visual Studio 17 2022" -
Not recommended :
-
Too many build artifacts (e.g.,
.o,.obj,.vcxproj,.sln,CMakeCache.txt, etc.) are placed inside the source directory. -
Switching between different build systems or CMake options (e.g., different generators or toolchains) may cause conflicts.
-
Difficult to isolate multiple build configurations (e.g., Debug vs Release).
-
Some tools/scripts assume a clean separation of source and build.
-
-
-
Use a separate
build/directory and always build out-of-source.-
CMake documentation strongly encourages out-of-source builds.
-
-
Properties
-
CMake generates a
.slnand.vcxprojwith extra Visual Studio-specific information. -
Ex :
# Use solution folders to organize projects set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Variables
-
Ex :
# Configure CMake global variables
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Distribution")
Meson
-
-
Similar to CMake.
-
-
Needs to be used from Visual Studio CMD.
-
Modern alternative to CMake, generates
NinjaorVisual Studio.
Premake
-
Generates
Makefile,Visual Studio,Xcodefrom Lua scripts.
autotools
-
GNU.
-
Uses
configure+Makefile.into generateMakefile(old, but still used).